/* LottoLuck.h
 * Author: mtreece
 * Date: 03/02/2010
 * Purpose:
 *  Main header file for LottoLuck.cpp
 */

#ifndef LOTTOLUCK_H
#define LOTTOLUCK_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <list>

#include "TicketLine.h"
#include "Ticket.h"
#include "Definitions.h"
#include "ConfReader.h"
#include "DefConfFile.h"

#define REVISION_DATE "04/22/2010"

#define CONF_FILE_NAME "LottoLuck.conf"

/* No problemo */
#define EXIT_OKAY 0

/* Unknown, generic error */
#define EXIT_ERROR -1

#define HELP_MESSAGE \
	"Usage:\n" \
	" lottoluck [--mode=M] [--config=F] [--numtrials=T] [--cpt=C] [--defsrc=S] [--verbose] [--about] [--help]\n" \
	"\n" \
	"\t--mode=M   M can be either...\n" \
	"\t   INTERACTIVE.....Run the program via a menu-driven approach; this is the default.\n" \
	"\t   SINGLE_WINNER...Runs the simulation as if a single ticket is the winner. i.e., \n" \
	"\t                   the argument, numtrials, will specify the number of randomly \n" \
	"\t                   selected (\"purchased\") tickets and a single 'winner' ticket \n" \
	"\t                   will be checked against each of them to calculate winning amounts.\n" \
	"\t   RANDOM_TICKETS..Runs the simulation as if the player purchases a new, random \n" \
	"\t                   ticket-set for each drawing (specified by numtrials); this\n" \
	"\t                   simulation would generate a new Ticket-set of count 'cpt' for \n" \
	"\t                   each trial, and each trial would get a new, random 'winning' \n" \
	"\t                   ticket to be checked against.\n" \
	"\t                   NOTE: You must specify --cpt=C option for this simulation. C is \n" \
	"\t                         the number of chances per ticket.\n" \
	"\t   DEFINED_TICKET..Runs the simulation with ticket-data input, representing a fixed \n" \
	"\t                   Ticket-set that the player desires to play each time.  Each trial\n" \
	"\t                   will have a new winner-ticket generated and checked against this \n" \
	"\t                   input ticket. Specify the source of this ticket with --defsrc=S.\n" \
	"\t--config=F.........F represents the file name of a configuration file to open. By \n" \
	"\t                   default, the configuration file name is 'LottoLuck.conf'.\n" \
	"\t--numtrials=T......Represents the number of drawings that will occur.\n" \
	"\t--cpt=C............Represents the number of \"Chances Per Ticket\", which is the\n" \
	"\t                   number of ticket-lines on a Ticket.\n" \
	"\t--defsrc=S.........Specify this option when using DEFINED_TICKET mode; S is either a \n" \
	"\t                   filename or can be '-', to represent stdin. The format for this file\n" \
	"\t                   will be whitespace delimited numbers, PB number at the end; eg:\n" \
	"\t                        10 15 20 25 30 17\n" \
	"\t--verbose..........Specifies the program will be verbose in tickets it finds matching \n" \
	"\t                   any value; results will be printed to stderr for proper filtering. \n" \
	"\t--about............A simple about-me option.  Run this if you're interested in knowing \n" \
	"\t                   more about the programmer or inspiration for this program, etc.\n" \
	"\t--help.............What you're seeing now!\n"

#define ABOUT_MESSAGE \
	"****************************************\n" \
	"****                                ****\n" \
	"**           ~  LottoLuck  ~          **\n" \
	"****                                ****\n" \
	"****************************************\n" \
	"   \"...all that glitters is gold...\"\n" \
	"                 - Stairway to Heaven\n" \
	"\n" \
	"       Author: Michael Tyler Reece (mtreece)\n" \
	"Last revision: " REVISION_DATE "\n" \
	"      Website: mtreece.net \n" \
	"  (rarely updated due to lack of time)\n" \
	"\n" \
	"The purpose of this program is to allow the user to establish a sense of how the \n" \
	"lottery works and to get a tangible feeling for just how difficult it is to make\n" \
	"any money in the lottery (specifically Powerball lottery). Other worthy purposes \n" \
	"of this program could be in its use to obtain pseudo-random data off of a \n" \
	"lottery-simulation.\n" \
	"\n" \
	"This program is BINARY, which means its programmer...\n" \
	"  1) Doesn't understand how licensing works\n" \
	"  2) Doesn't care how licensing works\n" \
	"  3) Would prefer credit if you modify this in any way\n" \
	"  4) Isn't responsible if your computer breaks\n" \
	"  5) Would appreciate financial donations if you like his work\n" \
	"  6) Is ultimately just some guy who loves programming\n" \
	"\n" \
	"If you have any questions, comments, concerns, bug-reports, or if you'd just like to \n" \
	"say \"Hey!\", send me an email to:    mtreece   AT   ncsu   DOT   edu\n" \
	"\n" \
	"This program was proudly written in VIM on a Linux platform!\n" \

/** define a few things... **/

#define MAXBUFF 500  /** Refactor later for better security. **/

/* ProgramControl handles main flow of program. */
typedef enum{
	ERROR,
	HELP,
	ABOUT,
	INTERACTIVE,
	SINGLE_WINNER,
	RANDOM_TICKETS,
	DEFINED_TICKET,
} ProgramControl;

/* Environment is a simple way to pass around the
 * parameters given to me. */
typedef struct{
	int argc;

	/* Cannot make this a *[], since it needs 
	 * to know spacing information?
	 * (i.e. amount of space to reserve)
	 */
	char **argv;
} Environment;

/* Structure to hold information obtained via
 * the commandline.
 */
typedef struct{
	char mode[MAXBUFF];
	char confFile[MAXBUFF];
	char numTrials[MAXBUFF];
	char cpt[MAXBUFF];
	char defsrc[MAXBUFF];

	/* Have something for the
	 * main() method to print
	 * if necessary...  */
	char errmsg[MAXBUFF];

	int verbose;
	int about;
	int help;
} PassedArgs;

/** sign our functions... **/
ProgramControl parseArgs(Environment*, int*, PassedArgs*);

int hasArg(Environment*, const char*, int*);

void writeWebster(Definitions*);
void generateConfFile(const char*);
void getTimestamp(char*);

void interactive(PassedArgs*, Definitions*);
void single_winner(PassedArgs*, Definitions*);
void random_tickets(PassedArgs*, Definitions*);
void defined_ticket(PassedArgs*, Definitions*);
void routine_tasks(Definitions*);

Ticket* getSrcTicket(char*);

void help(void);
void about(void);

#endif
